import java.util.Deque;
import java.util.LinkedList;

/**
 * @author VernHe
 * @date 2021年05月30日 22:21
 */
public class Solution_0114 {
    public void flatten(TreeNode root) {
        if (root == null) {
            return;
        }
        Deque<TreeNode> deque = new LinkedList();
        preOrder(root, deque);
        TreeNode node = new TreeNode();
        while (!deque.isEmpty()) {
            node.right = deque.removeFirst();
            node.right.left = null;
            node = node.right;
        }
    }

    private void preOrder(TreeNode root, Deque deque) {
        if (root == null) {
            return;
        }
        deque.addLast(root);
        preOrder(root.left,deque);
        preOrder(root.right,deque);
    }
}
